from django.test import TestCase
from PIL import Image
# Create your tests here.
import random

num = 1
# while True:
#     num += 1
#     print(num)
#     if num == 4:
#         break

# a=()
# while num <=3:
#     print(num)
#     num+=1

x = tuple([random.randint(0, 233) for i in range(3)])
print(x)


def valid_check(request):
    """  1、前台渲染图片
      <img src="{% url 'valid_check' %}" alt="" height="30" width="240">
    with open("static/image-20210220102205414.png", "rb") as f:
        data = f.read()
    return HttpResponse(data)
    """
    # pip install pillow
    # new(mode, size, color=0)

    """ 局限性、每次生成img都会在本地保存为一个文件，增加了IO对性能的压力
    img = Image.new("RGB", (320, 33), vaild_random(3))
    with open("static/img.png", "wb") as f:
        img.save(f, "png")
    with open("static/img.png", "rb") as f:
        data = f.read()
    return HttpResponse(data)
    """
    # 第三种，推荐使用这种
    img = Image.new("RGB", (320, 33), vaild_random(3))
    io = BytesIO()
    img.save(io, "png")  # 直接通过二进制形式写到内存中
    data = io.getvalue()  # 获取到数据给它返回
    return HttpResponse(data)


import random
from io import StringIO
# x = random.randrange(random.randint(65, 90),random.randint(97, 122), random.randint(1, 9))
# print(x)
# x = chr(random.choice([random.randint(65, 90),random.randint(97, 122)]))
# print(x)


# get_num = chr(ran_num) if ran_num > 9 else ran_num
# f = StringIO()
# for i in range(5):
#     ran_num = random.choice([random.randint(65, 90),random.randint(97, 122),random.randint(0, 9)])
#     get_num = chr(ran_num) if ran_num > 9 else ran_num
#     f.write(str(get_num))
# print(f.getvalue())

# a="AAA"
# print(a.lower())

a="a"

